import { SharedEntity } from 'src/api/shared/entities/shared.entity';
import { UserEntity } from 'src/api/user/entities/user.entity';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { ArticleEntity } from './article.entity';

@Entity('article_like')
export class ArticleLikeEntity extends SharedEntity {
  @Column({
    type: 'varchar',
    name: 'ip',
    length: 255,
    nullable: true,
    comment: 'ip',
  })
  ip: string;

  // 关联的用户
  @Column({
    type: 'varchar',
    name: 'user_id',
    length: 36,
    comment: '关联的用户ID',
  })
  userId: string;

  // 一个用户可以点赞多个
  @ManyToOne(() => UserEntity, (user) => user.articleCommentLikes, {
    onDelete: 'RESTRICT',
    onUpdate: 'RESTRICT',
  })
  @JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }])
  user: UserEntity;

  // 关联的文章
  @Column({
    type: 'varchar',
    name: 'article_id',
    length: 36,
    comment: '关联的文章ID',
  })
  articleId: string;

  // 一个文章可以多个点赞
  @ManyToOne(() => ArticleEntity, (article) => article.likes, {
    onDelete: 'RESTRICT',
    onUpdate: 'RESTRICT',
  })
  @JoinColumn([{ name: 'article_id', referencedColumnName: 'id' }])
  article: ArticleEntity;
}
